Add more error reporting for failing to join paths
authorAlex Crichton <alex@alexcrichton.com>
Wed, 11 Feb 2015 17:21:04 +0000 (09:21 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 11 Feb 2015 17:21:04 +0000 (09:21 -0800)
Hopefully this will help diagnose #1083

src/cargo/util/errors.rs
src/cargo/util/paths.rs

index 5b03a9668f7d403c37e234dfaab90a23603a9a49..a13e7410f4bb2284084d6f7312d548a73440d1bc 100644 (file)
@@ -70,6 +70,16 @@ impl<T, E: CargoError> ChainError<T> for Result<T, E> {
     }
 }
 
+impl<T> ChainError<T> for Box<CargoError> {
+    fn chain_error<E2, C>(self, callback: C) -> CargoResult<T>
+                         where E2: CargoError, C: FnOnce() -> E2 {
+        Err(Box::new(ChainedError {
+            error: callback(),
+            cause: self,
+        }) as Box<CargoError>)
+    }
+}
+
 impl<T> ChainError<T> for Option<T> {
     fn chain_error<E, C>(self, callback: C) -> CargoResult<T>
                          where E: CargoError, C: FnOnce() -> E {
index 3284681c2b620abf09e4666af6204a325ad33861..f02fefe104ab65ef42020686054cf07cc60e6fad 100644 (file)
@@ -4,7 +4,7 @@ use std::old_io;
 use std::old_path::BytesContainer;
 use std::os;
 
-use util::{human, CargoResult};
+use util::{human, internal, CargoResult, ChainError};
 
 pub fn realpath(original: &Path) -> old_io::IoResult<Path> {
     const MAX_LINKS_FOLLOWED: usize = 256;
@@ -47,8 +47,12 @@ pub fn realpath(original: &Path) -> old_io::IoResult<Path> {
 #[allow(deprecated)] // need an OsStr-based Command first
 pub fn join_paths<T: BytesContainer>(paths: &[T], env: &str)
                                      -> CargoResult<Vec<u8>> {
-    os::join_paths(paths).map_err(|e| {
-        human(format!("failed to join search paths together: {}\n\
-                       Does ${} have an unterminated quote character?", e, env))
+    os::join_paths(paths).or_else(|e| {
+        let paths = paths.iter().map(|p| Path::new(p)).collect::<Vec<_>>();
+        internal(format!("failed to join path array: {:?}", paths)).chain_error(|| {
+            human(format!("failed to join search paths together: {}\n\
+                           Does ${} have an unterminated quote character?",
+                          e, env))
+        })
     })
 }